import java.net.UnknownHostException;
import java.util.Set;
import com.mongodb.DBAddress;
import com.mongodb.Mongo;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import com.mongodb.DBCursor;
import com.mongodb.MongoException;

public class accessDB {
	
	public static String DBpath = "ec2-50-19-154-92.compute-1.amazonaws.com";
	public static int DBport = 27017;
	public static String DBname = "cluster_data";
	public static DB db;
	
	public static Mongo connect()
	{
		Mongo m;
		try {
			m = new Mongo(new DBAddress(DBpath, DBport, DBname));
		} catch (UnknownHostException e) {
			System.out.println("UnknownHostException error encountered. " +
			"Host attempted: " + DBname + " port: " + DBport);
			System.out.println(e);
			return null;
		} 
		System.out.println("Connetion established to: " + DBpath + " Database: " + 
				DBname + "port: " + DBport);
		
		db = m.getDB(DBname);
		
		return m;
	}
	
	public static DBCollection getCollection(String collectionName)
	{
		DBCollection coll = db.getCollection(collectionName);
		return coll;		
	}
	
	public static int test(Mongo m)
	{
		Set DBset;
		
		DBset = db.getCollectionNames();
		
		DBset.toString();
		System.out.println(DBset);
		return 0;
	}
}
